﻿Imports System.Data.OleDb
Imports System.Data
Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            UpdateRep()
        Catch

        End Try
    End Sub

    Private Sub UpdateRep()
        Dim objBl = New BL()
        ''Dim objDal = New DL()
        Dim strSelect As String = ""
        rpRecipe.DataSource = ""
        Dim dbconn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("/App_Data/KitchenCompition.mdb"))

        strSelect = "select * from reciepe order by currentrating desc"
        Dim dt As DataTable = objBl.GetDataAccess(strSelect, dbconn)


        Dim RecipeDataTable As DataTable = dt
        Dim cloneDataTable As DataTable = RecipeDataTable.Clone()

        For i As Integer = 0 To 2
            cloneDataTable.ImportRow(RecipeDataTable.Rows(i))
        Next

        Dim dv As DataView = New DataView(cloneDataTable)


        rpRecipe.DataSource = dv
        rpRecipe.DataBind()
       
        topcontributor()
    End Sub


    'Public Shared Function getLatestFourActive() As DataView
    '    Dim productDataTable As DataTable = getAll().ToTable()
    '    Dim cloneDataTable As DataTable = productDataTable.Clone()

    '    For i As Integer = 0 To 3
    '        cloneDataTable.ImportRow(productDataTable.Rows(i))
    '    Next
    '    Return New DataView(cloneDataTable)
    'End Function

    Private Sub topcontributor()
        Dim objBl = New BL()
        ''Dim objDal = New DL()
        Dim strSelect As String = ""
        rpRecipe.DataSource = ""
        Dim dbconn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("/App_Data/KitchenCompition.mdb"))

        strSelect = "select Email, count(Email) as ecount from Reciepe group by Email"
        Dim dt As DataTable = objBl.GetDataAccess(strSelect, dbconn)

        Dim dvData As DataView = New DataView(dt)
        dvData.RowFilter = "ecount > " & ConfigurationManager.AppSettings("topcontributor").ToString()

        repTopcontributor.DataSource = dvData
        repTopcontributor.DataBind()

    End Sub

    Public Shared Function Limit(Desc As Object, length As Integer) As String
        Dim strDesc As New StringBuilder()
        strDesc.Insert(0, Desc.ToString())

        If strDesc.Length > length Then
            Return strDesc.ToString().Substring(0, length) & "..."
        Else
            Return strDesc.ToString()
        End If
    End Function

End Class